package queue_sim

import "math"
import "math/rand"

type PoissonProcess struct {
      lambda float64
      max_time float64
      jump []float64
}

func ExpDist (lambda float64) float64 {
      u := rand.Float64()
      t := - 1.0 / lambda * math.Log (1 - u) 
      return t
}

func MakePoissonProcess (lambda float64, max_time float64) * PoissonProcess {
      var pp PoissonProcess
      pp.lambda = lambda
      pp.max_time = max_time
      pp.jump = make ([]float64, 0)

      var t float64

      for ;t < max_time; {
            jt := ExpDist (lambda)
            t += jt
            pp.jump = append (pp.jump, t)
      }

      return &pp
}

func (pp * PoissonProcess) NJump () int {
      return len(pp.jump)
}

func (pp * PoissonProcess) JumpTime (i int) float64 {
      return pp.jump[i]
}
